package com.rui.study.com.rui.study.feign.hystrix;

import feign.Contract;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
@RestController
@Import(ProducerRegistrar.class)
public class FeignHystrixDemo {

	public static void main(String[] args) {
		SpringApplication.run(FeignHystrixDemo.class, args);
	}

	@Bean
	public Contract defaultContrat() {
		return new feign.Contract.Default();
	}

	@Autowired
	private Producer producer;


	@Autowired
	private KeyApi keyApi;


	@GetMapping("/v1/salt")
	public Map<String, Object> getSalt() {
		return keyApi.getSalt("1234");
	}


	@GetMapping("/v1/producer")
	public String getProducer() {
		return producer.getName();
	}
}
